import org.junit.Test

class Solution {
    @Test
    fun test() {
        val nums1 = intArrayOf(1, 2, 3, 0, 0, 0)
        val m = 3
        val nums2 = intArrayOf(2, 5, 6)
        val n = 3
        merge(nums1, m, nums2, n)
    }

    fun merge(nums1: IntArray, m: Int, nums2: IntArray, n: Int) {
        val temp: IntArray = IntArray(m + n) { 0 }

        var p1: Int = 0
        var p2: Int = 0
        var i: Int = 0
        while (p1 < m || p2 < n) {
            if (p1 < m && p2 < n) {
                if (nums1[p1] <= nums2[p2]) {
                    temp[i] = nums1[p1]
                    println("[1],${temp.contentToString()}")
                    p1++
                    i++
                    continue
                } else if (nums1[p1] > nums2[p2]) {
                    temp[i] = nums2[p2]
                    println("[2],${temp.contentToString()}")
                    p2++
                    i++
                    continue
                }
            } else if (p1 < m) {
                temp[i] = nums1[p1]
                println("[4],${temp.contentToString()}")
                p1++
                i++
                continue
            } else {
                temp[i] = nums2[p2]
                println("[5],${temp.contentToString()}")
                p2++
                i++
                continue
            }
        }
        for (j in 0 until m + n) {
            nums1[j] = temp[j]
        }
    }
}